<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<title>新建多群引流</title>
	<link rel="stylesheet" href="/layui/css/layui.css">
    <link rel="stylesheet" href="/fission/css/iconfont.css">
	<style type="text/css">
		body{
			background: #e9e9e9;
		}
		/*公共头部带搜索*/
		.public_container{
			margin: 20px;
			background: #fff;
		}
		.public_title_container{
			height: 54px;
			padding: 0 20px;
			font-size: 14px;
			display: flex;
			align-items: center;
			background: #f9f9f9;
			border-bottom: 1px solid #f0f0f0;
			justify-content: space-between;
		}
		.public_title_container a{
			fill: #999;
		}
		/*公共表单部分*/
		.public_form_container{
			padding: 20px 20px 40px 20px;
		}
		.public_form_content{
			padding: 24px 40px 24px 0;
			background: #fff;
			border: 1px solid #e9e9e9;
			margin-bottom: 8px;
		}
		.public_form_List{
			margin-bottom: 10px;
		}
		.public_form_List:last-child{
			margin-bottom: 0px;
		}
		.public_formTitle_container lable{
			font-size: 13px;
			font-weight: bold;
		}
		.newcreatGroup_otherTips_container{
			color: #999;
			font-size: 14px;
			padding-top: 10px;
		}
		.table-stop{
			text-align: center;
			cursor: pointer;
			color: #2196f3;
			margin-top: 10px;
		}
		.table-input{
			height: 38px;
			line-height: 1.3;
			border-width: 1px;
			border-style: solid;
			background-color: #fff;
			border-radius: 2px;
			border-color: #e6e6e6;
			padding-left: 10px;
			margin: 10px;
			width: 150px;
		}
		.service-card {
		  padding: 0 7px;
		  color: rgba(0,0,0,.65);
		  line-height: 28px;
		  font-size: 13px;
		  display: inline-block;
		  margin: 0 8px 0 5px;
		  -webkit-box-sizing: border-box;
		  box-sizing: border-box;
		  white-space: nowrap;
		  background: #fafafa;
		  border: 1px solid #e9e9e9;
		  border-radius: 4px;
		  position: relative;
		}
		.service-card i {
		  font-size: 14px;
		  display: inline-block;
		  color: #7da3d1;
		  margin-right: 2px;
		}
		.service-card .close {
		  position: absolute;
		  top: -13px;
		  right: -8px;
		  opacity: .6;
		  cursor: pointer;
		}
		.service-card .close:hover {
		  opacity: 1;
		}
	</style>
</head>
<body>

	<form class="layui-form" id="form1">
		

		<div class="public_container">
			<!-- /*公共头部带搜索*/ -->
			<div class="public_content">
				<div class="public_title_container">
					<p>新建多群引流</p>
					<a href="javascript:history.back(-1)">
						<svg t="1599462684269" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="8055" width="20" height="20"><path d="M501.2992 273.408l1.024-156.16L184.65792 379.904l314.29632 266.1376 0.95232-149.2992c313.86624 42.5984 178.29888 231.3216-0.5632 410.2144 619.5712-404.3776 251.01312-590.6432 1.95584-633.5488z" p-id="8056"></path></svg>
					</a>
				</div>

			</div>
			<!-- /*公共头部带搜索*/ end -->
			<!-- 公共表单部分 -->
			<div class="public_form_container">
				<div class="public_form_content">
					<div class="public_form_List">
						<div class="public_formTitle_container">
							<lable class="layui-form-label">群码名称：</lable>
						</div>
						<div class="public_formOther_container">
							<div class="layui-input-block">
								<input type="text" name="name" value="{$multigroup->name}" required  lay-verify="required" placeholder="请输入群码名称" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
				</div>

			
				
				<div class="public_form_content">
					
					<div class="public_form_List shareuser">
						<div class="public_formTitle_container">
							<lable class="layui-form-label">客服人员：</lable>
						</div>
						<div class="public_formOther_container">
							<div class="layui-input-block">
								<span class="layui-btn layui-btn-primary" id="addGroup">+ 添加群二维码</span>
							</div>
							<div class="layui-input-block">
								<table class="layui-table" >
								  <colgroup>
								      <col>
								      <col>
								      <col  width="130">
								      <col>
								    </colgroup>
								    <thead>
								      <tr>
								      	<th>群二维码</th>
								      	<th>自定义群名称</th>
								        <th>群描述</th>
								        <th>操作</th>
								      </tr> 
								    </thead>
								    <tbody id="groupChatCon">
								    {if $multigroup->data}
								    {loop $multigroup->data as $k => $group}
										<tr class="groupItems">
										<input type="hidden" id="item_id_{$k}" name="item.id[]" value="{$group['id']}" required>
										<td><input type="text" id="item_name_{$k}" name="item.name[]" onclick="selectAuto({$k})" value="{$group['name']}" required readonly class="table-input" placeholder="+选择自动拉群"></td>
										<td><input  type="text"  name="item.selfname[]" class="table-input" value="{$group['selfname']}" required></td>
										<td><textarea name="item.desc[]">{$group['desc']}</textarea></td>
										<td><button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="delitem(this)">删除</button></td>
										</tr>
									{/loop}
									{else}
										<tr class="groupItems">
										<input type="hidden" id="item_id_0" name="item.id[]" value="{}" required>
										<td><input type="text" id="item_name_0" onclick="selectAuto(0)" value="" required readonly class="table-input" placeholder="+选择自动拉群"></td>
										<td><input  type="text"  name="item.selfname[]" value="" class="table-input" required></td>
										<td><textarea name="item.desc[]"></textarea></td>
										<td><button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="delitem(this)">删除</button></td>
										</tr>
								    {/if}
								    </tbody>
								</table>
							</div>
						</div>
					</div>
				</div>

				<div class="public_form_content">
					<div class="public_form_List">
						<div class="public_formTitle_container">
							<lable class="layui-form-label">功能设置：</lable>
						</div>
						<div class="public_formOther_container" >
							<div class="layui-input-block" id="selectTime_container">
								<input type="radio" lay-filter="selectTime" name="type" value="2" title="新客户添加员工进群" {if $multigroup->add_group_type == 2} checked {/if}>
								<input type="radio" lay-filter="selectTime" name="type" value="1" title="新客户直接进群" {if $multigroup->add_group_type == 1} checked {/if}>
								
							</div>
						</div>
						<div class="layui-input-block newcreatGroup_otherTips_container">
							<!-- <p>（客户添加时无需企业成员确认，自动成为好友）</p> -->
						</div>
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-input-block">
						<a class="layui-btn" lay-submit lay-filter="formDemo">立即提交</a>
						<!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
					</div>
				</div>
			</div>
			<!-- 公共表单部分 end-->
		</div>
	</form>
	<script src="/cdn/jquery.js"></script>
	<script src="/layui/layui.js"></script>
	<script src="/js/ajax.js"></script>
	<script type="text/javascript">
		
		// 弹窗
		layui.use('layer', function(){
		  var layer = layui.layer;
		}); 
		// 表单
		layui.use('form', function(){
		  var form = layui.form;
		  
		  //监听提交
		  form.on('submit(formDemo)', function(data){
		    //layer.msg(JSON.stringify(data.field));
		    //return false;
			var formData = $('#form1').serialize();	
			myAjaxPost(false, true, '', formData, function (resp) {
				console.log(resp)
				if (resp.status == 'success') {
					tusi(resp.msg);
					setTimeout(function(){
						location.href = 'index.html'; 
					},2000);
				}else{
					alert(resp.msg);
				}
			});
		  });

		  // 自动标签
		  form.on('switch(autoLable)', function(data){
		      console.log(data.elem.checked); //是否被选中，true或者false
		      if(data.elem.checked == true){
		      	$("#autoLableContainer").show();
		      }else{
		      	$("#autoLableContainer").hide();
		      }
		      form.render();
		  });
		});
		
	</script>
	<script type="text/javascript">
		$('#addPeople').on('click',function(){
			layer.open({
			  type: 2,
			  title: '请选择使用人员',
			  shadeClose: true,
			  shade: 0.2,
			  area: ['700px', '530px'],
			  content: 'select_user-{$contactWay->id}.html'
			}); 
		})
		$('#addLable').on('click',function(){
			layer.open({
			  type: 2,
			  title: '请选择标签',
			  shadeClose: true,
			  shade: 0.2,
			  area: ['700px', '530px'],
			  content: 'select_tag.html'
			}); 
		})
		$('#addGroup').on('click',function(){
			let lastTr = $("#groupChatCon tr").length
			let html = '';
			html += '<tr class="groupItems">'
			html += '<input type="hidden" id="item_id_'+lastTr+'" name="item.id[]" value="" required>'
			html += '<td><input type="text" id="item_name_'+lastTr+'" required name="item.name[]" onclick="selectAuto('+lastTr+')" readonly class="table-input" placeholder="+选择自动拉群"></td>'
			html += '<td><input  type="text"  name="item.selfname[]" value="" required class="table-input"></td>'
			html += '<td><textarea name="item.desc[]"></textarea></td>'
			html += '<td><button type="button" class="layui-btn layui-btn-sm layui-btn-danger" onclick="delitem(this)">删除</button></td>'
			html += '</tr>'
			$("#groupChatCon").append(html);

		})
	</script>
	
	<script>
	layui.use(['element', 'layer', 'upload'], function () {
	  var layer = layui.layer;
	});
	function selectAuto(x){

		layer.open({
		  type: 2,
		  title: ' ',
		  shadeClose: true,
		  shade: 0.2,
		  area: ['700px', '530px'],
		  content: 'select_auto_group_chat.html?x='+x
		}); 
	}

	function checkNum(a){
		var val = a.value;
		if (val=='') { 
　　　　　　a.value = 500;
　　　　}else if(!(/(^[1-9]\d*$)/.test(val))){
			a.value = 500;
		}else if(val > 500){
			a.value = 500;
		}
	}
	function delitem(a){
		if($("#groupChatCon tr").length == 1){
			alert('至少保留一个群二维码');
			return false;
		}
		$(a).parents('tr.groupItems').remove();
		var tr = $("#groupChatCon tr");
		tr.each(function(i,e){
			e.firstElementChild.id = 'item_id_'+i;
			e.children[1].firstElementChild.id = 'item_name_'+i;
			e.children[1].firstElementChild.setAttribute('onclick','selectAuto('+i+')');
		})
	}
	</script>
</body>
</html>